<!DOCTYPE HTML>
<html>

<head>
    <title>proton.js-zone-dead</title>
    <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta charset="utf-8">
    <style type="text/css">
        body {
            background-color: #333333;
            margin: 0px;
            overflow: hidden;
        }
        
        #container {
            width:100%;
            height:100%;
        }
        
        #testCanvas {
            background: #000000;
        }
    </style>
</head>

<body>
    <div id="container">
        <canvas id="testCanvas"></canvas>
    </div>
    <script src="../../lib/requestAnimationFrame.min.js"></script>
    <script src="../../lib/stats.min.js"></script>
    <script src="//localhost:3001/build/proton.js"></script>
    <script>
        var canvas;
        var context;
        var proton;
        var renderer;
        var emitter;
        var stats;
        var textures;

        main();

        function main() {
            canvas = document.getElementById("testCanvas");
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
            //context = canvas.getContext('2d');
            addStats();

            textures = [];
            var str = 'proton';
            for (var i = 0; i < str.length; i++) {
                var url = 'image/' + str.substr(i, 1) + '.png';
                textures.push(url);
            }

            createProton();
            tick();
        }

        function addStats() {
            stats = new Stats();
            stats.setMode(2);
            stats.domElement.style.position = 'absolute';
            stats.domElement.style.left = '0px';
            stats.domElement.style.top = '0px';
            document.getElementById('container').appendChild(stats.domElement);
        }

        function createProton() {
            proton = new Proton;
            emitter = new Proton.Emitter();
            //add rate
            emitter.rate = new Proton.Rate(new Proton.Span(10, 20), new Proton.Span(.1, .5));
            //add initialize

            emitter.addInitialize(new Proton.Mass(1));
            emitter.addInitialize(new Proton.Body(textures));
            emitter.addInitialize(new Proton.Life(8, 15));
            emitter.addInitialize(new Proton.Position(new Proton.CircleZone(canvas.width / 2, canvas.height / 2, 100)));
            emitter.addInitialize(new Proton.Velocity(new Proton.Span(2, 4), new Proton.Span(0, 360), 'polar'));
            //add behaviour

            emitter.addBehaviour(new Proton.Alpha(1, 0), new Proton.Color('random'));
            emitter.addBehaviour(new Proton.Scale(Proton.getSpan(.2, 1)));
            emitter.addBehaviour(new Proton.RandomDrift(10, 10, .05));
            var crosszone = new Proton.CrossZone(new Proton.CircleZone(canvas.width / 2, canvas.height / 2, 280), 'bound');
            emitter.addBehaviour(crosszone);
            
            emitter.emit();
            proton.addEmitter(emitter);

            //add render
            renderer = new Proton.WebGLRenderer(canvas);
            renderer.blendFunc("SRC_ALPHA", "ONE");
            proton.addRenderer(renderer);
        }

        function tick() {
            requestAnimationFrame(tick);

            stats.begin();
            proton.update();
            stats.end();
        }
    </script>
</body>

</html>